<?php
Template::AddJs("picnet.table.filter.min");
Template::AddJs("jquery.tablesorter.min");
Template::AddCss("tablesorter/style");
?>
<script type="text/javascript">
$(function() {
  $("#student-records").tablesorter({ 
        headers: { 
            4: { 
                sorter: false 
            },
            5: { 
                sorter: false 
            },
            6: { 
                sorter: false 
            },
            7: { 
                sorter: false 
            },
            8: { 
                sorter: false 
            },
            9: { 
                sorter: false 
            },
            10: { 
                sorter: false 
            } 
        } 
    }); 
  $('#student-records').tableFilter();
  
});
</script>
<form method="post" action="">
  <div>
    <span><strong>Filter by:</strong></span>
    <span style="margin-left: 10px;">Class:</span>
      <input type="checkbox" name="FR" <?php if (strstr($_SESSION["class"], "FR")) echo "checked"; ?> />FR
      <input type="checkbox" name="SO" <?php if (strstr($_SESSION["class"], "SO")) echo "checked"; ?> />SO
      <input type="checkbox" name="JR" <?php if (strstr($_SESSION["class"], "JR")) echo "checked"; ?> />JR
      <input type="checkbox" name="SR" <?php if (strstr($_SESSION["class"], "SR")) echo "checked"; ?> />SR
    <span style="margin-left: 10px;">Alphabet:</span>
      <select name="alpha1">
        <?php 
          for($i=65; $i<91; $i++){
            $checked = "";
            if ($i == ord($_SESSION["alpha"]{0}))
              $checked = "selected";
            echo "<option value=\"".chr($i)."\" $checked>".chr($i)."</option>";
          }
        ?>
      </select>
      <select name="alpha2">
        <?php 
          for($i=65; $i<91; $i++){
            $checked = "";
            if ($i == ord($_SESSION["alpha"]{1}))
              $checked = "selected";
            echo "<option value=\"".chr($i)."\" $checked>".chr($i)."</option>";
          }
        ?>
      </select>
      <input type="submit" name="filter" value="Filter" />
  </div>
</form>
<table id="student-records" class="tablesorter records">
  <thead>
    <tr>
      <th>ID</th>
      <th>Name</th>
      <th filter-type="ddl">Class</th>
	    <th filter-type="ddl">College</th>
      <th filter-type="ddl">withd</th>
      <th>withdate</th>
      <th filter-type="ddl">enrstat</th>
      <th filter-type="ddl">plnret</th>
      <th filter-type="ddl">specpgm</th>
      <th filter-type="ddl">acadact</th>
      <th filter="false">Action</th>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($students as $student): 
      $index++; $a = ord($_SESSION["alpha"]{0}); $b = ord($_SESSION["alpha"]{1}); $last = ord($student->last{0});
      if ($last < $a || $last > $b)
        continue;
      if (strstr($_SESSION["class"], $student->class."") === false)
        continue;
    ?>
    <tr>
      <td><?php echo $student->id; ?></td>
      <td><?php echo "$student->last, $student->first"; $email = trim($student->email); if (!empty($email)) echo "<br />$student->email"; ?></td>
      <td><?php echo $student->class; ?></td>
      <td><?php echo $student->college; ?></td>
      <td><?php echo $student->withd; ?></td>
      <td><?php echo $student->withdate == "0" ? "" : $student->withdate; ?></td>
      <td><?php echo $student->enrstat; ?></td>
      <td><?php echo $student->plnret; ?></td>
      <td><?php echo $student->specpgm; ?></td>
      <td><?php echo $student->acadact; ?></td>
      <td><a href="?q=student/cr/<?php echo "".($index - 1); ?>">Create Reminder</a></td>
    </tr>
    <?php endforeach; ?>
  </tbody>
</table>